package com.baidu.track.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.baidu.track.R;
import com.baidu.track.model.StationModel;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class StationActivity extends BaseActivity{

    private LinearLayout llAreas;
    StationModel station;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        llAreas = (LinearLayout) findViewById(R.id.wr_areas);
        setTitle("停留报表");
        setOptionsButtonInVisible();
        Intent intent = getIntent();
         station = (StationModel) intent.getSerializableExtra("station");
        showData();
    }
    private void showData(){
        for (int i = 0; i < station.getArr().size(); i++) {
            String startTime = station.getArr().get(i).getStartTime();
            String endTime = station.getArr().get(i).getEndTime();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
            Date d1=null;
            Date d2=null;
            try {
                 d1 = sdf.parse(startTime);
                 d2 = sdf.parse(endTime);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            String address = station.getArr().get(i).getAddress();
            LinearLayout llWashingRoomItem = new LinearLayout(this);
            llWashingRoomItem.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            llWashingRoomItem=(LinearLayout)getLayoutInflater().inflate(R.layout.activity_area,null);
            TextView tvStart = (TextView) llWashingRoomItem.findViewById(R.id.tv_wr_areaname);
            TextView tvEnd = (TextView) llWashingRoomItem.findViewById(R.id.tv_wr_mt_man);
            TextView tvAdd = (TextView) llWashingRoomItem.findViewById(R.id.tv_wr_dc_man);
            TextView tvIntev = (TextView) llWashingRoomItem.findViewById(R.id.tv_wr_xbc_man);
            tvStart.setText(startTime);
            tvEnd.setText(endTime);
            tvAdd.setText(address);
            long diff = d2.getTime() - d1.getTime();
            long diffSeconds = diff / 1000 % 60;//秒
            long diffMinutes = diff / (60 * 1000) % 60;//分钟
            long diffHours = diff / (60 * 60 * 1000) % 24;//小时
            long diffDays = diff / (24 * 60 * 60 * 1000);//天
            tvIntev.setText(diffDays+"天"+diffHours+"小时"+diffMinutes+"分钟"+diffSeconds+"秒");
            //动态设置layout_weight权重设置表格宽度
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1.5f);
            tvStart.setLayoutParams(lp);
            lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
            tvEnd.setLayoutParams(lp);
            lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
            tvAdd.setLayoutParams(lp);
            lp = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
            tvIntev.setLayoutParams(lp);
            llAreas.addView(llWashingRoomItem);
        }
    }
    @Override
    protected int getContentViewId() {
        return R.layout.activity_station;
    }
}
